package chapter8;

import chapter5.entity.Admin;
import chapter5.service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/dr")
public class drServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置请求编码格式
        request.setCharacterEncoding("utf-8");
        //设置响应的格式
        response.setContentType("text/html;charset=utf-8");
        //设置响应的编码格式
        response.setCharacterEncoding("utf-8");




        String name=request.getParameter("name");
        String pwd=request.getParameter("pwd");
        Admin admin=new Admin(-1,name,pwd);
        AdminServiceImpl impl=new AdminServiceImpl();
        int count=impl.loginAdmin(admin);
        if(count>0){
            request.getRequestDispatcher("chapter8/drs.jsp").forward(request,response);
        }else{
            response.sendRedirect("chapter8/logins.jsp");
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
